import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/index',
    name: 'index',
    redirect: '/greet',
    component: () => import('../views/index.vue'),
    children: [
     
    ]
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  let token = localStorage.getItem("token")
  if (to.fullPath == "/") {
    console.log(1);
    next()  
  }else{
    if(token){
        next()
    }else{
      next('/')
       console.log(2);
    }
  }
})
export default router
